package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.EmpSocDispatchExample.E_CHILD_COMPANY_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.E_COMPANY_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.E_FUND_END_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.E_FUND_END_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.E_FUND_START_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.E_FUND_START_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.E_ID_CARD;
import static org.jsola.hr.example.EmpSocDispatchExample.E_IS_HAS_LESS;
import static org.jsola.hr.example.EmpSocDispatchExample.E_NAME;
import static org.jsola.hr.example.EmpSocDispatchExample.E_PHONE;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_DISPATCH_EMP_ADD_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_DISPATCH_EMP_LESS_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_END_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_END_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_PROG_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_START_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.E_SOC_START_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.E_STATUS;
import static org.jsola.hr.example.EmpSocDispatchExample.N_CHILD_COMPANY_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.N_COMPANY_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.N_FUND_END_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.N_FUND_END_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.N_FUND_START_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.N_FUND_START_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.N_ID_CARD;
import static org.jsola.hr.example.EmpSocDispatchExample.N_IS_HAS_LESS;
import static org.jsola.hr.example.EmpSocDispatchExample.N_NAME;
import static org.jsola.hr.example.EmpSocDispatchExample.N_PHONE;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_DISPATCH_EMP_ADD_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_DISPATCH_EMP_LESS_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_END_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_END_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_PROG_ID;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_START_DATE_END;
import static org.jsola.hr.example.EmpSocDispatchExample.N_SOC_START_DATE_START;
import static org.jsola.hr.example.EmpSocDispatchExample.N_STATUS;

/**
 * 员工社保派单状态表
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpSocDispatchQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_CHILD_COMPANY_ID, example = E_CHILD_COMPANY_ID)
    @Length(max = 32)
    private String childCompanyId;

    @ApiParam(value = N_NAME, example = E_NAME)
    @Length(max = 50)
    private String name;

    @ApiParam(value = N_PHONE, example = E_PHONE)
    @Length(max = 20)
    private String phone;

    @ApiParam(value = N_ID_CARD, example = E_ID_CARD)
    @Length(max = 32)
    private String idCard;

    @ApiParam(value = N_SOC_DISPATCH_EMP_ADD_ID, example = E_SOC_DISPATCH_EMP_ADD_ID)
    @Length(max = 32)
    private String socDispatchEmpAddId;

    @ApiParam(value = N_SOC_PROG_ID, example = E_SOC_PROG_ID)
    @Length(max = 32)
    private String socProgId;

    /**
     * 社保停缴时间查询范围
     */
    @ApiParam(value = N_SOC_START_DATE_START, example = E_SOC_START_DATE_START)
    private Date socStartDateStart;
    @ApiParam(value = N_SOC_START_DATE_END, example = E_SOC_START_DATE_END)
    private Date socStartDateEnd;


    /**
     * 公积金停缴时间查询范围
     */
    @ApiParam(value = N_FUND_START_DATE_START, example = E_FUND_START_DATE_START)
    private Date fundStartDateStart;
    @ApiParam(value = N_FUND_START_DATE_END, example = E_FUND_START_DATE_END)
    private Date fundStartDateEnd;


    @ApiParam(value = N_SOC_DISPATCH_EMP_LESS_ID, example = E_SOC_DISPATCH_EMP_LESS_ID)
    @Length(max = 32)
    private String socDispatchEmpLessId;

    /**
     * 社保停缴时间查询范围
     */
    @ApiParam(value = N_SOC_END_DATE_START, example = E_SOC_END_DATE_START)
    private Date socEndDateStart;
    @ApiParam(value = N_SOC_END_DATE_END, example = E_SOC_END_DATE_END)
    private Date socEndDateEnd;


    /**
     * 公积金停缴时间查询范围
     */
    @ApiParam(value = N_FUND_END_DATE_START, example = E_FUND_END_DATE_START)
    private Date fundEndDateStart;
    @ApiParam(value = N_FUND_END_DATE_END, example = E_FUND_END_DATE_END)
    private Date fundEndDateEnd;


    @ApiParam(value = N_IS_HAS_LESS, example = E_IS_HAS_LESS)
    private Boolean isHasLess;

    @ApiParam(value = N_STATUS, example = E_STATUS)
    private Integer status;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpSocDispatchQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

